import axios from "axios"
import { notification } from 'antd';

let server = axios.create({
    baseURL: '',
    timeout: 10 * 1000
}
)
server.interceptors.request.use(
    (config) => {
        config.headers.token = localStorage.getItem("token")
        return config;
    },
    (error) => {
        return Promise.reject(error)
    }
)
server.interceptors.response.use(
    (res) => {
        return res
    },
    (error) => {
        if (error.response.status === 401) {
            notification.error({ message: '登陆过期,请重新登陆!' })
        } else if (error.response.status === 404) {
            notification.error({ message: '访问路径有误!' })
        } else if (error.response.status === 500) {
            notification.error({ message: '服务器内部错误!' })
        }
        return Promise.reject(error)
    }
)

export default server